package com.ruoyi.web.controller.luoma;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.UserProfile;
import com.ruoyi.system.service.UserProfileService;
import com.ruoyi.web.controller.irdms.InspectionController;
import org.apache.ibatis.annotations.Param;
import org.aspectj.weaver.loadtime.Aj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import static com.alibaba.fastjson2.JSON.toJSON;

/**
 * @Author: azh
 * Created on 2025-3-10 22:07
 */
@RestController
public class UserProfileController {

    private static final Logger logger = LoggerFactory.getLogger(UserProfileController.class);

    @Autowired
    private UserProfileService profileService;

    @PostMapping("/insertUserProfile")
    public AjaxResult insertUserProfile(@RequestBody UserProfile profile) {
        if (profile == null) {
            return AjaxResult.error("参数为null");
        }
        profileService.insertUserProfile(profile);
        logger.info("insertUserProfile profile: {}", toJSON(profile));
        return AjaxResult.success();
    }

    @GetMapping("/selectUserProfileByUserId")
    public AjaxResult selectUserProfileByUserId(@Param("userId") Long userId) {
        if (userId == null) {
            return AjaxResult.error("参数UserId不可为null");
        }
        UserProfile profile = profileService.selectUserProfileByUserId(userId);
        logger.info("selectUserProfileByUserId userId: {}, profile: {}", userId, toJSON(profile));
        return AjaxResult.success(profile);
    }

    @PostMapping("/updateUserProfile")
    public AjaxResult updateUserProfile(@RequestBody UserProfile profile) {
        if (profile == null) {
            return AjaxResult.error("参数为null");
        }
        profileService.updateUserProfile(profile);
        logger.info("updateUserProfile: {}", toJSON(profile));
        return AjaxResult.success();
    }

    @PostMapping("/deleteUserProfileByUserId")
    public AjaxResult deleteUserProfileByUserId(Long userId) {
        if (userId == null) {
            return AjaxResult.error("参数UserId不可为null");
        }
        profileService.deleteUserProfileByUserId(userId);
        return AjaxResult.success();
    }
}
